﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AjaxPro;

namespace EnvironmentManagerSystem.SearchQuery
{
    public partial class SDSTabtwo : System.Web.UI.Page
    {
        public Boolean isAdmin = false;

        //窗体加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(EnvironmentManagerSystem.HuanJing.HuanJing_Tabtwo));
            //是否首次加载
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                clear();
                Q();
                DataBing();
            }
        }

        public void clear()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox) (this.Form.Controls[i] as TextBox).Text = "";
                    else if (this.Form.Controls[i] is Label) (this.Form.Controls[i] as Label).Text = "";
                }
            }
            catch { }
        }

        private void Q()
        {

            if (BLL.Role.GetQ(int.Parse(Session["ID"].ToString()), "21"))
            {
                foreach (Control c in this.Controls)
                {
                    if (c.GetType() == typeof(TextBox))
                    {
                        ((TextBox)c).Enabled = true;
                    }
                    else
                    {
                        //((TextBox)c).Enabled = false;
                    }
                }
            }
        }
        protected void Button8_Click(object sender, EventArgs e)
        {
            check();
        }

        /// <summary>
        /// 权限验证
        /// </summary>
        public void check()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox)
                    {
                        (this.Form.Controls[i] as TextBox).ReadOnly = true;
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// 进行数据绑定
        /// </summary>
        public void DataBing()
        {
            try
            {
                Hashtable list = EnvironmentManagerSystem.BLL.HuanJing.GetShengTai(Session["pjName"] != null ? Session["pjName"].ToString() : "");
                if (list != null)
                {
                    foreach (DictionaryEntry de in list)
                    {
                        if (this.frm.FindControl(de.Key.ToString()) != null)
                        {
                            ((TextBox)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                        }
                    }
                }
            }
            catch
            {
                Jscript.Alert("数据异常", this.Page);
            }
        }

        /// <summary>
        /// 编辑数据库
        /// </summary>
        [AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
        public void EditTable(string CName, string CValue)
        {
            try
            {
                if (Session["pjName"] != null)
                {
                    EnvironmentManagerSystem.BLL.HuanJing.EditTableShengTai(CName, CValue, Session["pjName"] != null ? Session["pjName"].ToString() : "");
                }
            }
            catch { }
        }
    }
}
